import { Injectable } from '@angular/core';
import { BaseService } from '@core/routes-services/base.service';
import { CacheService } from '@core/routes-services/cache.service';
import { HttpClient } from '@angular/common/http';

/**
 * 商盟意向、签约 服务
 */
@Injectable()
export class MarketAgentService extends BaseService {

  constructor(http: HttpClient, cacheService: CacheService) {
    super(http, cacheService);
  }

  base_url: any = 'api/market/agent';


  /**
   * 分页
   *
   * @param user
   * @returns {Promise<any>}
   */
  wishPagination(page: any, keyword: any,districtId:any,salesmanId:any,marketLevelId:any): Promise<any> {
    const url = this.base_url + '/wish/pagination';
    if(keyword){
      page['_filter_like_name'] = keyword;
    }
    if(districtId){
      page['_filter_eq_districtId'] = districtId;
    }
    if(salesmanId){
      page['_filter_eq_salesmanId'] = salesmanId;
    }
    if(marketLevelId){
      page['_filter_eq_marketLevelId'] = marketLevelId;
    }

    return this.post(url, page);
  }

  signPagination(page: any, keyword: any,districtId:any,salesmanId:any,marketLevelId:any): Promise<any> {
    const url = this.base_url + '/sign/pagination';
    if(keyword){
      page['_filter_like_name'] = keyword;
    }
    if(districtId){
      page['_filter_eq_districtId'] = districtId;
    }
    if(salesmanId){
      page['_filter_eq_salesmanId'] = salesmanId;
    }
    if(marketLevelId){
      page['_filter_eq_marketLevelId'] = marketLevelId;
    }

    return this.post(url, page);
  }
  /**
   * 修改
   *
   * @param id
   * @param entity
   * @returns {Promise<any>}
   */
  toSignAgent(id: any, entity: any): Promise<any> {
      const url = this.base_url + '/' + id;
      return this.post(url, entity);
  }

  /**
   * 为y意向用户设置业务员
   *
   * @param id
   * @param entity
   * @returns {Promise<any>}
   */
  setSalesman(id: any, entity: any): Promise<any> {
    console.log(entity)
      const url = this.base_url + '/'+id+'/'+entity.id+'/'+entity.districtId ;
      return this.put(url, entity);
  }

  /**
   * 获取查看详情
   *
   * @param id
   * @returns {Promise<any>}
   */
  detail(id: any): Promise<any> {
    const url = this.base_url + '/' + id;
    return this.get(url);
  }

  /**
   * 删除
   *
   * @param ids
   * @returns {Promise<any>}
   */
  deleteEntity(ids): Promise<any> {
    const url = this.base_url + '/';
    return this.delete(url, ids);
  }

}
